home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_06
/
1106130a
< prev
next >
Wrap
Text File
|
1993-02-26
|
885b
|
39 lines
/* cp.c: Copy files */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
extern int filecopy(char *, char *);
static void cp(char *, char *);
main(int argc, char **argv)
{
int i;
struct stat finfo;
char *target = argv[argc-1];
/* Make sure target is a directory */
assert(argc >= 3);
assert(stat(target,&finfo) == 0 &&
(finfo.st_mode & S_IFDIR));
/* Copy files */
for (i = 1; i < argc-1; ++i)
cp(argv[i],target);
return 0;
}
static void cp(char *file, char *target)
{
static char newfile[FILENAME_MAX];
/* Combine target and source file for a full pathname */
sprintf(newfile,"%s/%s",target,file);
fprintf(stderr,"copying %s to %s\n",file,newfile);
if (filecopy(file,newfile) != 0)
fputs("cp: Copy failed\n",stderr);
}